//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class CalcModeRecord : WorkbookLevelRecord
    {
        private ushort fAutoRecalc = 1;

        public CalcModeRecord(Worksheet worksheet)
        {
           //\\ this.fAutoRecalc = worksheet.CalculationProperties.
        }

        public CalcModeRecord()
        {
        }

        public override void Apply(BiffReaderWorkbookContext context)
        {
            switch (fAutoRecalc)
            {
                case 0:
                    context.Workbook.CalculationProperties.CalculationMode = CalculationMode.Manual;
                    break;
                case 1:
                    context.Workbook.CalculationProperties.CalculationMode = CalculationMode.Automatic;
                    break;
                case 2:
                    context.Workbook.CalculationProperties.CalculationMode = CalculationMode.AutomaticNoTable;
                    break;
            }
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.CalcMode; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.Writer.Write(fAutoRecalc);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            fAutoRecalc = context.ReadUInt16();
        }
    }
}